package answer

import "sort"

func maxIceCream(costs []int, coins int) int {
	sort.Ints(costs)
	result := 0
	for coins > 0 && result < len(costs) {
		coins -= costs[result]
		if coins >= 0 {
			result++
		}
	}
	return result
}
